Skip to content

Deck panel: take a signed update over Wi-Fi, verified with libsodium, switched only then, rolled back if it doesn't come up (#690) - #714

Open
Skeyelab wants to merge 25 commits into
mainfrom
690-wifi-update
Open

Skeyelab wants to merge 25 commits into
mainfrom
690-wifi-update

Conversation

@Skeyelab

Copy link
Copy Markdown
Member

Closes #690

Summary

The deck panel takes a signed firmware update over Wi-Fi.

  • Before anything reaches the spare slot: Ed25519 over the manifest's exact bytes, with the same keys as the app, from the same test vector as Updater: signed firmware releases the app can fetch #689 (ADR 0012).
  • Writing: the image goes into the spare slot and is hashed (SHA-256) as it arrives.
  • Switch: the boot slot changes only when every check passes.
  • Fallback: if the new image doesn't come up, the panel rolls back.
core 0  update task (prio 2, 8 KB): lwIP socket :3310, select() 100 ms, one client ("refused busy" for a second)
          update_link  → frames (M ≤ 32 KB, S = 64, I ≤ 4 KB, D) → update_session
            Verify = libsodium crypto_sign_verify_detached     Hasher = libsodium crypto_hash_sha256
            Slot   = esp_ota (next partition; begin with the real size; end checks the image; set_boot)
            keys   = release_keys (empty until the owner makes them → every update "unknown-key")
          switch → floor saved as pending for the target slot → restart
boot    verifyRollbackLater() = true, so update_boot decides from the loop's chores:
          confirm: saved Wi-Fi joined (or the setup network up) and :3310 listening, within 120 s → mark valid, raise floor
          else roll back. The display feed is never required.
core 1  loop: while flash is written, a still "Updating…" screen; render and refresh are skipped

Protocol for the app side (#691): docs/DECK-PANEL-UPDATE-PROTOCOL.md.

Evidence

  • Native tests (all red first, one commit per slice): 232 pass.
    • manifest: a strict reader.
    • session: trusted keys, signature, format, floor and lowest_allowed, slot size, hash, and nothing switched on a short or long image.
    • link: frame caps from the header alone, one connection, idle 3 s before the manifest and 10 s mid-image. A zero-length read restarts the idle clock, so a long erase doesn't time out.
    • boot: the confirm rule.
    • release_keys: they equal the app's ReleaseKeys.swift (a Python test in CI).
    • floor: only ever rises, only to a version.
    • release_check: RFC 8032 TEST 1 and the updater's own CryptoKit fixture, read from its file. A whole signed update runs through the session with real libsodium; one image byte or one manifest byte changed is refused.
  • Mutation checks: a hash that drops a byte, a verify that always passes, and a link that stamps only non-empty reads all fail the tests.
  • Two builds of one library: board and native use two builds of libsodium. Native uses the system copy (brew 1.0.22 on the Mac, Ubuntu's libsodium-dev in CI, whose version the Deck panel job logs). The board uses the ESP32 libs' espressif__libsodium (component 1.0.22), already in the default link. The shared RFC 8032 and CryptoKit vector test is what ties them together.
  • CI's libsodium install: a timeout and one retry, so it can't hang the merge queue. A workflow step isn't unit-testable.
  • Board code (src/update_wifi.*, five main.cpp calls, wifi_link::setup_up()): can't be unit-tested. An Embedded Firmware Engineer agent wrote it. It has not been compiled locally: the board build is blocked for this session, so CI's Deck panel job is its first build, and the first proof that libsodium links on the board.

Embedded Firmware Engineer notes

  • Task: core 0, priority 2: above idle and below the feed's receive task (5), lwIP (18), esp_timer (22) and Wi-Fi (23).
    • Stack: 8 KB, estimated from the Ed25519 verify path and not measured. The task prints its high-water mark after each connection.
    • Sockets: plain lwIP sockets, never WiFiServer, which isn't thread-safe.
  • Erase vs idle: erasing a big image takes about 4 s (up to about 15 s for a full slot). The board restarts the idle clock after each read. The app must wait that long for ok manifest.
  • Still screen:
    • The task only sets an atomic. The loop shows a black full-screen object on lv_layer_top, draws it once, then skips render and refresh until the write ends.
    • During writes the cache is off and non-IRAM ISRs are held off, so no_latch, missed and late rise in the perf line. That is expected.
    • On abort or refusal the overlay is hidden. LVGL invalidates a hidden object first (lv_obj.c:120-121), so the first frame after it is a full redraw; the driver's direct mode takes a full-screen area.
  • NVS: namespace deckupdate, apart from Wi-Fi's, so a hold-reset forget can't touch the floor. Keys: floor, and a pending pend_floor/pend_slot.
    • At boot, a pending record for another slot is dropped.
    • One for this slot while not on trial is applied. This covers power loss between mark-valid and the floor write.
  • Power loss:
    • Mid-write: the old image boots; the boot slot never changed.
    • Between set_boot and the pending write: the new image boots on trial without raising the floor. That's the one gap.
  • Wi-Fi never comes up after an update: the panel rolls back at 120 s. A crash or watchdog reset during the trial rolls back too, through the bootloader.
  • Not verified without a board build:
    • that it compiles: lwIP's timeval, TCP_NODELAY, MSG_DONTWAIT; the Preferences overload; LVGL 9.1's lv_obj_remove_flag;
    • that <sodium.h> from espressif__libsodium links. The symbols are in the .a, but linking isn't proven yet;
    • stack use, erase times, and the 500 ms still-screen handshake.

On the board (the coordinator flashes; the owner looks)

  • Normal running: the panel answers on 3310.
  • An update refused: with today's empty key list, every update is refused as unknown-key, and nothing is written.
  • After keys exist: a signed update switches, confirms on Wi-Fi, and raises the floor. A bad image is refused. A panel that can't join rolls back at 120 s.
  • An aborted update: the deck is fully redrawn. Expect a skipped frame or two and a late clock right after the hold (a whole-screen redraw); that isn't a fault.
  • After an update: the perf line's resyncs stay at 0 or 1, with no resync storm.

Merge Danger

Door: two-way for the code. A floor written to NVS can't be lowered, by design (#689).

Blast Radius: deck panel. With the key list empty, no update can be taken.

main.cpp, platformio.ini and wifi_link lines agreed with agent2. This PR lands last in the main.cpp order (#666, #664, #702, #711, then this); main gets merged in before it's armed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1

Skeyelab and others added 23 commits November 21, 2026 07:33
…ut short or deeply nested (#690)

Passed when written; mutation checks: dropping the one-image rule, the trailing-bytes check or the depth limit fails it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…known key or bad signature is refused (#690)

The signature check is a seam (a fake here) until the owner picks the Ed25519 source.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…o boot (#690)

The slot erases only the image's own size. The size and hash checks come next.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…another format, no panel image or too big is refused (#690)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…, before their bytes are kept (#690)

Manifest at most 32 KB, signature exactly 64 bytes, image chunk at most 4 KB, done empty. The unknown-type test
passed when written (an unknown frame already fell through to a refusal); it now has its own check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…dropped connections end with nothing switched (#690)

3 s before the manifest, so a stray connection can't hold busy; 10 s mid-image.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…ode's network) and the update server are up (#690)

Never on the display feed, so updating with DeckBridge closed doesn't roll a good image back. Otherwise it rolls back
after 120 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…mpty until the owner makes them (#690)

test_release_keys.py checks the panel's list equals ReleaseKeys.swift; a mistyped key is left out (mutation check:
skipping the hex check fails it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…h libsodium, against the updater's vectors (#690)

RFC 8032 TEST 1 and the updater's own CryptoKit fixture, read from its file so the two can't drift. Native links
the system libsodium; the board links the copy in the ESP32 libs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…hunk as the session's hasher (#690)

FIPS 180-2 B.1 and B.2 in uneven pieces, and start() beginning again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…sodium's checks, and the two ways it's refused (#690)

A test key from a fixed seed, made in the test; never a release key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…rsion, so a bad write can't refuse every update (#690)

update_floor::raised keeps the higher of the floor and the one a confirmed image brings; update_session's version
compare is shared, not copied.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
… so a long erase after "ok manifest" doesn't time out (#690)

The board passes one after each received(), stamped after the work. Pins existing behavior (mutation: stamping only
non-empty reads fails it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
…10 on core 0, the spare slot, the floor, the rollback (#690)

src/update_wifi: an lwIP-socket server task on core 0 running update_link; an esp_ota Slot adapter; libsodium's
Ed25519 and SHA-256 as the session's checks; the floor in its own NVS namespace, raised only when the new image
confirms itself; verifyRollbackLater() overridden so update_boot decides (confirm on network + server up within
120 s, else roll back); a still "Updating…" screen while flash is written, the loop skipping render and refresh.
main.cpp gains five calls (agreed with agent2). Board code: not unit-testable; written with an Embedded Firmware
Engineer agent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
Skeyelab and others added 2 commits November 23, 2026 00:45
…ter (#690, #689)

Red first: test_release_keys.py (app 2 keys, panel 0) and the native test,
flipped from an empty list to the owner's primary and backup.
Reviewed by an Embedded Firmware Engineer agent: only the Wi-Fi update's
key lookup changes; updates signed by these keys now reach the rest of
the checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VCgWWsrZ4EvHNNNTAe7RC1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deck panel firmware: two app slots and a signed update over Wi-Fi

1 participant